package com.github.freewu.mvp.view.status;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;

import com.github.freewu.mvp.view.StatusView;

/**
 *
 * Created by free on 16-7-20.
 */
public class SimpleStatusView extends StatusView {
    LoadingView loadingView;
    ErrorView errorView;
    ReloadView reloadView;

    public SimpleStatusView(Context context) {
        super(context);
    }

    public SimpleStatusView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public SimpleStatusView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public View getLoadingView() {
        if (loadingView==null){
            loadingView=new LoadingView(getContext());
        }
        loadingView.startProgress();

        return loadingView;
    }

    @Override
    public View getErrorView() {
        if (errorView==null){
            errorView=new ErrorView(getContext());
        }
        if (loadingView!=null){
            loadingView.cancelProgress();
        }
        return errorView;
    }

    @Override
    public View getReloadView() {
        if (reloadView==null){
            reloadView=new ReloadView(getContext());
        }
        if (loadingView!=null){
            loadingView.cancelProgress();
        }
        return reloadView;
    }
    /**
     * 显示重新加载视图
     */
    public void showReloadView(String message){
        reloadView.setVisibility(View.VISIBLE);
        normalView.setVisibility(View.GONE);
        errorView.setVisibility(View.GONE);
        loadingView.setVisibility(View.GONE);

        reloadView.setErrorText(message);
    }

    @Override
    public void onCreate() {

    }

    @Override
    public void onDestroy() {
        if (loadingView!=null){
            loadingView.cancelProgress();

            loadingView.removeProgress();
        }
    }
}
